package com.littleshu.test;


/**
 * 题目：输入一行字符，分别统计出其中英文字母、空格、数字和其它字符的个数<br>
 * 程序分析：利用while语句,条件为输入的字符不为'\n'
 * 
 * @author littleshu
 *
 */
public class Question7 implements RunTest {
	static int bigLetterCount = 0;
	static int smallLetterCount = 0;
	static int spaceCount = 0;
	static int numberCount = 0;
	static int otherCount = 0;
	
	public static void main(String[] args) {
		new Question7().runTest();
	}

	@Override
	public void runTest() {
		String str = "sAdfs324324 3# 2ff!!";

		for (int i = 0; i < str.length(); i++) {

			if (CharType.isBigLetter(str.charAt(i))) {
				bigLetterCount++;
				continue;
			}
			if (CharType.isSmallLetter(str.charAt(i))) {
				smallLetterCount++;
				continue;
			}
			if (CharType.isSpace(str.charAt(i))) {
				spaceCount++;
				continue;
			}
			if (CharType.isNumber(str.charAt(i))) {
				numberCount++;
				continue;
			}
			otherCount++;
		}
		System.out.println("大写字母有" + bigLetterCount + "个");
		System.out.println("小写字母有" + smallLetterCount + "个");
		System.out.println("数字有" + numberCount + "个");
		System.out.println("空格有" + spaceCount + "个");
		System.out.println("其它字符有" + otherCount + "个");
	}

}

/**
 * 根据ASCII码值范围来确定字符的类型
 * 
 * @author littleshu
 *
 */
class CharType {
	public static boolean isBigLetter(char c) {
		return (c >= 65 && c <= 90);
	}

	public static boolean isSmallLetter(char c) {
		return (c >= 97 && c <= 122);
	}

	public static boolean isSpace(char c) {
		return c == 32;
	}

	public static boolean isNumber(char c) {
		return (c >= 48 && c <= 57);
	}

}